package com.xky.mybatis.dao;

import com.xky.mybatis.domain.Test;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author keying.xia
 * @date 2017/12/8
 */
@Mapper
@Repository
public interface TestMapper {

    @Insert("INSERT INTO `demo`.`test` (`id`,`name`,`age`) values (#{id},#{name},#{age})")
    int add(@Param("id") Integer id,@Param("name") String name, @Param("age") Integer age);

    @Delete("delete from `demo`.`test` where id = #{id}")
    int delete(@Param("id") Integer id);

    @Update("update `demo`.`test` set name = #{name}, age = #{age} where id = #{id}")
    int update(@Param("name") String name,@Param("age") Integer age,@Param("id") Integer id);

    @Select("select * from `demo`.`test`")
    @Results(
            {
                @Result(property = "name",column = "name",javaType = String.class),
                @Result(property = "age",column = "age",javaType = Integer.class)
            }
    )
    List<Test> getAll();

    @Select("select * from `demo`.`test` where id = #{id}")
    @Results(
            {
                    @Result(property = "name",column = "name",javaType = String.class),
                    @Result(property = "age",column = "age",javaType = Integer.class)
            }
    )
    Test getOne(@Param("id") Integer id);

}
